package com.kj.xuyuan.base;

import android.app.Activity;
import android.content.Context;
import com.kj.xuyuan.util.LogUtils;
import com.kj.xuyuan.util.SPUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Activity管理器
 */

public class ActivityCollector {
    public static List<Activity> activities = new ArrayList<>();

    public static void addActivity(Activity activity) {
        activities.add(activity);
    }

    public static void removeActivity(Activity activity) {
        activities.remove(activity);
    }

    public static void logout(Context context) {
        SPUtils.setBooleanData(context,"isLogin",false);
        for (Activity activity : activities) {
            if (!activity.isFinishing()) {
                activity.finish();
            }
        }

//        android.os.Process.killProcess(android.os.Process.myPid());
    }

    public static String getTopActivityName(){
        String name = activities.get(activities.size()-1).getClass().getSimpleName();
        return name;
    }

    public static boolean getTopActivityIsCallActivity(){

        LogUtils.e("TAG","getTopActivityName ="+getTopActivityName());

        if(getTopActivityName().equals("VideoActivity")){
            return true;
        }

        if(getTopActivityName().equals("VoiceActivity")){
            return true;
        }

        return false;
    }

    public static void finishActivity(String activityName){
        for (Activity activity : activities) {
            if (activity.getClass().getSimpleName().equals(activityName)) {
                activity.finish();
            }
        }
    }
}
